import java.util.StringTokenizer;
import java.util.Vector;

class P10700 {

	public static void main(String[] args) {
		try {
		long cases = Integer.parseInt(readLn());
		for (long k = 0; k < cases; k++) {
			Vector op = getOp(readLn());
			Vector aux = (Vector) op.clone();
//			System.out.println(op);
//			System.out.println(aux);
			long max = getMax(op);
			long min = getMin(aux);
			System.out.println("The maximum and minimum are " + max + " and " + min +".");
		}
		} catch (Exception e) {
			while (true) {
				
			}
		}
	}

	private static long getMin(Vector aux) {
		multiplyAll(aux);
		addAll(aux);
		return ((Long)aux.elementAt(0)).longValue();
	}

	private static void addAll(Vector aux) {
		int addIndex = getAddIndex(aux);
		while (addIndex > -1) {
			Long x = new Long(((Long)aux.elementAt(addIndex - 1)).longValue() + ((Long)aux.elementAt(addIndex + 1)).longValue());
			aux.setElementAt(x, addIndex);
			aux.removeElementAt(addIndex + 1);
			aux.removeElementAt(addIndex - 1);
			addIndex = getAddIndex(aux);
		}		
	}

	private static void multiplyAll(Vector aux) {
		int multiplyIndex = getMultiplyIndex(aux);
		while (multiplyIndex > -1) {
			Long x = new Long(((Long)aux.elementAt(multiplyIndex - 1)).longValue() * ((Long)aux.elementAt(multiplyIndex + 1)).longValue());
			aux.setElementAt(x, multiplyIndex);
			aux.removeElementAt(multiplyIndex + 1);
			aux.removeElementAt(multiplyIndex - 1);
			multiplyIndex = getMultiplyIndex(aux);
		}		
	}

	private static int getAddIndex(Vector aux) {
		return aux.indexOf("+");
	}

	
	private static int getMultiplyIndex(Vector aux) {
		return aux.indexOf("*");
	}

	private static long getMax(Vector op) {
		addAll(op);
		multiplyAll(op);
		return ((Long)op.elementAt(0)).longValue();
	}

	private static Vector getOp(String line) {
		Vector op = new Vector();
		StringTokenizer st = new StringTokenizer(line, "*+", true);
		while (st.hasMoreTokens()) {
			String bit = st.nextToken();
			if (Character.isDigit(bit.charAt(0))) {
				op.addElement(new Long(bit));
			} else {
				op.addElement(bit);
			}
		}
		return op;
	}


	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString()).trim();
	}

}
